<template>
  <div class="index">
    <Location class="index-location" type="processing" />
    <div class="index-merchant">
      <div class="index-meichant-list">
        <div
          v-for="item in list.otherList"
          :key="item.goods_id"
          class="index-meichant-list-item"
          @click="handleOneGoods(item.goods_id)"
        >
          <div class="index-meichant-list-item-top">
            <div class="index-meichant-list-item-top-tips">
              <img
                v-if="item.biaoqian_1"
                class="index-meichant-list-item-top-tip"
                :src="filter.tagOneFilter(item.biaoqian_1)"
              />
              <img
                v-if="item.biaoqian_2"
                class="index-meichant-list-item-top-tip"
                :src="filter.tagTwoFilter(item.biaoqian_2)"
              />
            </div>
            <img
              class="index-meichant-list-item-top-good"
              :src="imgUrl + item.original_img"
            />
          </div>
          <div class="index-meichant-list-item-down">
            <div class="index-meichant-list-item-down-text">
              {{ item.goods_name || "暂无名称" }}
            </div>
            <div class="index-meichant-list-item-down-text">
              {{ item.shop_name || "暂无店铺" }}
            </div>
            <div class="index-meichant-list-item-down-text">
              {{ item.shop_address || "暂无地址" }}
            </div>
          </div>
        </div>
      </div>
      <div class="index-meichant-pagination">
        <Pagination
          v-model:page="field.formData.page"
          v-model:row="field.formData.page_size"
          v-model:total="field.total"
          @changePage="field.handleChangePage"
        />
      </div>
    </div>
  </div>
</template>
<script setup>
import { ToastBottom, setObj, getObj } from "@/utils/index";
import { onMounted, computed, ref, reactive, toRefs, inject } from "vue";
import { useRoute, useRouter } from "vue-router";
import Location from "@/components/location/index";
import Pagination from "@/components/pagination/index";
//获取路由
const $_route = useRoute();
const $_router = useRouter();
//获取接口
const $_api = inject("$api");

const imgUrl = computed(() => {
  return process.env.VUE_APP_BASE_API;
});

onMounted(() => {
  //获取其他商品
  api.getOtherGoods();
});
//获取接口
const api = reactive({
  //获取其他商品
  getOtherGoods: async () => {
    const results = await $_api.otherGoods({ type: 3, ...field.formData });
    if (results && results.status > 0) {
      console.log(results);
      field.total = results.num;
      list.otherList = results.data;
    }
  },
});
// 列表
const list = reactive({
  //其他商品
  otherList: [],
});

const field = reactive({
  formData: {
    page: 1,
    page_size: 16,
  },
  total: 0,
  handleChangePage: page => {
    console.log(page, "get");
    field.formData.page = page;
    api.getOtherGoods();
  },
});

const filter = reactive({
  tagOneFilter: status => {
    switch (Number(status)) {
      case 1:
        return require("@/assets/images/image(41).png");
      case 2:
        return require("@/assets/images/image(42).png");
    }
  },
  tagTwoFilter: status => {
    switch (Number(status)) {
      case 1:
        return require("@/assets/images/image(44).png");
      case 2:
        return require("@/assets/images/image(45).png");
    }
  },
});
const handleOneGoods = id => {
  $_router.push({
    path: `/goods`,
    query: {
      id,
    },
  });
};
</script>

<style lang="scss" scoped>
.index {
  @include flex(flex-start, center);
  flex-direction: column;
  margin: 5px auto 0;
  width: 1200px;
}
.index-location {
  flex-shrink: 0;
  width: 100%;
  height: 105px;
}
.index-merchant {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  margin-top: 13px;
  margin-bottom: 20px;
  width: 100%;
}
.index-meichant-list {
  @include flex(flex-start, center);
  flex-wrap: wrap;
  width: 100%;
}
.index-meichant-list-item {
  margin-right: calc((100% - 1168px) / 3);
  margin-bottom: 10px;
  width: 292px;
}
.index-meichant-list-item:nth-child(4n) {
  margin-right: 0;
}
.index-meichant-list-item-top {
  @include flex(center, center);
  position: relative;
  margin-bottom: 6px;
  width: 100%;
  height: 191px;
  background: #f6f6f6;
  box-shadow: 0px 2px 8px 0px rgba(202, 202, 202, 0.5);
  border-radius: 6px;
  z-index: 9;
}
.index-meichant-list-item-top-tips {
  @include flex(flex-start, center);
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99;
}
.index-meichant-list-item-top-tip {
  margin-bottom: 6px;
  width: 50px;
  height: 26px;
}
.index-meichant-list-item-top-tip:last-child {
  margin-bottom: 0px;
}
.index-meichant-list-item-top-good {
  width: 233px;
  height: 159px;
}
.index-meichant-list-item-down {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  width: 100%;
}
.index-meichant-list-item-down-text {
  @include text_cut_line;
  margin-top: 5px;
  width: 100%;
  height: 25px;
  font-size: 18px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 25px;
}
.index-meichant-pagination {
  width: 100%;
}
</style>
